<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100的整数" id="d1">
<input type="button" value="猜一猜" onclick="f()">
<div></div>
<script>
  //获取1-100的随机整数
  let x=parseInt(Math.random()*100)+1;
  console.log(x)
  let count=0;
  function f() {
      count++;
    let d = document.querySelector("#d1")
    let c = document.querySelector("div")
      if (d.value>x) {
        c.innerText = "猜大了"
      }else if (d.value<x) {
        c.innerText = "猜小了"
      }else{
        c.innerText = "恭喜你,第"+count+"次猜对了"
      }
  }
</script>
</body>
</html>